
<div class="content_wrapper">

    <div class="container-fluid">
        <div class="row">
            <div class="col-sm-12">
                <aside>
                    <header><i class="fa fa-fw fa-file"></i> 意向订单详情</header>
                    <section>
                        <div class="container-fluid">
                            <div class="row">
                                <div class="col-sm-12">
                                    <form class="form-horizontal" role="form" method="post" action="" data-validate="validate">
                                        <div class="form-group">
                                            <label class="col-sm-2 control-label">意向订单类型:</label>
                                            <div class="col-sm-4">
                                                <input type="text" class="form-control" placeholder="" name="type" value="" disabled>
                                            </div>
                                        </div>
                                        <hr/>
                                        <div class="title_bar">供应信息</div>
                                        <div class="form-group">
                                            <label class="col-sm-2 control-label">供应详情</label>
                                            <div class="col-sm-4">
                                                <div class="panel panel-default" >
                                                    <div class="panel-body" id="supply"></div>
                                                </div>

                                            </div>
                                        </div>
                                        <hr/>
                                        <div class="title_bar">求购信息</div>
                                        <div class="form-group">
                                            <label class="col-sm-2 control-label">求购详情</label>
                                            <div class="col-sm-4">
                                                <div class="panel panel-default" >
                                                    <div class="panel-body" id="demand"></div>
                                                </div>
                                            </div>
                                        </div>
                                        <hr/>

                                        <div class="title_bar">客户提交信息及过程</div>
                                        <div class="form-group">
                                            <label class="col-sm-2 control-label">客户意向信息</label>
                                            <div class="col-sm-4">
                                                <div class="panel panel-default" >
                                                    <div class="panel-body" id="intention_content"></div>
                                                </div>
                                            </div>
                                        </div>

                                        <div class="form-group">
                                            <label class="col-sm-2 control-label">状态:</label>
                                            <div class="col-sm-4">
                                                <select class="form-control" name="state" id="state">
                                                    <option value="-1">失败</option>
                                                    <option value="0">审核中</option>
                                                    <option value="1">跟进中</option>
                                                    <option value="2">交易成功</option>
                                                </select>
                                            </div>
                                        </div>
                                        <hr/>

                                        <div class="form-group">
                                            <div class=" col-sm-12">
                                                <button type="button" class="btn btn-primary J_ajaxSubmitBtn">提交</button>
                                            </div>
                                        </div>

                                    </form>
                                </div>
                            </div>
                        </div>
                    </section>
                </aside>
            </div>
        </div>
    </div>

</div>



<script>
    function validate($from) {
//        var title = $from.find('input[name="title"]');
//        if ($.trim(title.val()) == '') {
//            return '新闻标题不能为空';
//        }
        return true;
    }

    $(document).ready(function () {

        $("form").attr("action", common_conf.requestUrl+'intention/edit');

        getIntentionDetail($.getUrlVar('id'));
    });


    function getIntentionDetail(id) {
        $.ajax({
            type: 'post',
            url: common_conf.requestUrl+'intention/detail',
            contentType : 'application/json;charset=UTF-8',
            cache: false,
            data: '{"id":'+id+'}',
            dataType: 'json',
            beforeSend: function () {
            },
            success: function (returnData) {
                if(forceLogin(returnData)) return;
                var obj=returnData;
                if(obj.state=="success"){
                    initFormData(obj.data);
                }else{
                    alert("获取失败");
                }
            },
            error: function () {
                alert("未找到模板");
            }
        });
    }

    function initFormData($data) {
        $("#supply").html($data.supply);
        $("#demand").html($data.demand);
        $("#intention_content").html($data.content);
        var intention=$data.intention;
        $('form').append("<input type='hidden' name='id' value='"+intention.id+"'>");
        var type_text="";
        switch (intention.type){
            case 1:
                type_text="供应";
                break;
            case 2:
                type_text="求购";
                break;
            case 3:
                type_text="撮合";
                break;
        }
        $("input[name='type']").val(type_text);
        if(intention.state<2){
            $("#state option[value='"+intention.state+"']").attr("selected","selected");
        }else{
            $("#state option[value='2']").attr("selected","selected");
        }

    }

</script>